import 'katex/dist/katex.css'
import katex from 'katex'

export default {
  methods: {
    renderLatexHTML: function (content) {
      if (!content) {
        return content
      }
      content = content.replace(/</g, '&lt;')
      content = content.replace(/>/g, '&gt;')
      let oks = content.match(/([\\]\[.+?[\\]\])|([$].+?[$])/g)
      if (!oks) {
        return content
      }
      for (let ok of oks) {
        let tmp = ok.replace(/([\\]\[)|([\\]\])|[$]/g, '')
        tmp = tmp.replace(/&lt;/g, '<')
        tmp = tmp.replace(/&gt;/g, '>')
        let res = katex.renderToString(tmp)
        content = content.replace(ok, res)
      }
      return content
    }
  }
}
